package com.ymy.jedis;

import redis.clients.jedis.Jedis;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * @author ymy.hadoop
 * @date 2019/5/13 下午3:42
 */
public class jedis01 {

    public static void main(String[] args) {

        // redis链接不能使用localhost
        Jedis jedis = new Jedis("127.0.0.1");
        System.out.println("服务正在运行:" + jedis.ping());

        // stringDemo(jedis);
        // listDemo(jedis);
        keysDemo(jedis);
    }

    public static void stringDemo(Jedis jedis){

        jedis.set("str2","www.qq.com");
        String v2 = jedis.get("str2");
        System.out.println("v2:" + v2);
    }

    public static void listDemo(Jedis jedis){

        jedis.lpush("site-list","Runoob");
        jedis.lpush("site-list","Google");
        jedis.lpush("site-list","Taobao");

        List<String> list = jedis.lrange("site-list",0,-1);
        for (int i=0;i<list.size();i++){
            System.out.println("列表项为:" + list.get(i));
        }
    }

    public static void keysDemo(Jedis jedis){

       Set<String> keys = jedis.keys("*");
       Iterator<String> it = keys.iterator();
       while (it.hasNext()){
           String key = it.next();
           System.out.println("输出key为:" + key);
       }
    }
}
